<template>
  <div>
    <!-- 评论列表 -->
    <div class="cmt-list">
      <!-- 评论的 Item 项 -->
      <div class="cmt-item">
        <!-- 头部区域 -->
        <div class="cmt-header">
          <!-- 头部左侧 -->
          <div class="cmt-header-left">
            <img
              :src="item.aut_photo"
              alt=""
              class="avatar"
            >
            <span class="uname">{{item.aut_name}}</span>
          </div>
          <!-- 头部右侧 -->
          <div
            class="cmt-header-right"
            @click="show=!show"
          >
            <van-icon
              name="like"
              size="16"
              color="red"
              v-if="show"
              @click="like"
            />
            <van-icon
              v-else
              name="like-o"
              size="16"
              color="gray"
              @click="nolike"
            />
          </div>
        </div>
        <!-- 主体区域 -->
        <div class="cmt-body">
          {{item.content}}
        </div>
        <!-- 尾部区域 -->
        <div class="cmt-footer">{{fromTiem(item.pubdate)}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import { setLike, cancelSome } from '@/api/readArtcle.js'
// 导入局部组件必须在scrip里面导入,在App里面导入
export default {
  // 组件名称
  name: '',
  // 组件参数 接收来自父组件的数据
  props: { item: { type: Object } },
  // 接收局部注册的组件
  components: {},
  // 组件数据
  data () {
    return {
      show: this.item.is_liking
    }
  },
  methods: {
    fromTiem (val) {
      moment.locale('zh-cn')
      return moment(val).from(new Date())
    },
    // 点赞
    like () {
      // console.log(this.item);
      // 评论id
      cancelSome(this.item.com_id)
      // console.log('取消点赞');
    },
    // 取消点赞
    nolike () {
      setLike(this.item.com_id)
      // console.log(arr);
      // console.log(this.item.is_liking);
      // console.log('点赞');
    }
  }
}
</script>
<style lang='less' scoped>
.cmt-list {
  padding: 10px;
  .cmt-item {
    padding: 15px 0;
    + .cmt-item {
      border-top: 1px solid #f8f8f8;
    }
    .cmt-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .cmt-header-left {
        display: flex;
        align-items: center;
        .avatar {
          width: 40px;
          height: 40px;
          background-color: #f8f8f8;
          border-radius: 50%;
          margin-right: 15px;
        }
        .uname {
          font-size: 12px;
        }
      }
    }
    .cmt-body {
      font-size: 14px;
      line-height: 28px;
      text-indent: 2em;
      margin-top: 6px;
      word-break: break-all;
      text-align: left;
    }
    .cmt-footer {
      font-size: 12px;
      color: gray;
      margin-top: 10px;
      text-align: left;
    }
  }
}
</style>
